package com.tt.jshb.bill.zq;

import com.alibaba.fastjson.JSON;
import com.hzecool.common.utils.SPUtils;
import com.hzecool.core.base.TBasePresenter;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.tt.jshb.app.Constants;
import com.tt.jshb.app.ServerUrls;
import com.tt.jshb.bean.PayBean;
import com.tt.jshb.bean.YQBean;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by tu on 2018/11/28.
 */
public class YQPresenter extends TBasePresenter<YQView> {
    @Override
    protected void start() {

    }


    public void getData(String id) {
        OkGo.post(ServerUrls.ROUTER + "app/recyclingRecordsByXq.htm")
                .params("tokens", SPUtils.getString(Constants.SP_TOKENDS))
                .params("id",id)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        try {
                            YQBean bean = JSON.parseObject(s, YQBean.class);
                            if (bean.getCode() == 0) {
                                getView().onLoadList(bean);
                            } else {
                                getView().onLoadError(bean.getMsg());
                            }
                        } catch (Exception e) {
                        }
                    }
                });
    }

    public void payInfo(String id,String ts,String zf) {
        OkGo.post(ServerUrls.ROUTER + "app/recyclingRecordsByXqPay.htm")
                .params("tokens", SPUtils.getString(Constants.SP_TOKENDS))
                .params("id",id)
                .params("ts",ts)
                .params("zf",zf)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        try {
                            PayBean bean = JSON.parseObject(s, PayBean.class);
                            if (bean.getCode() == 0) {
                                getView().onPayResult(bean);
                            } else {
                                getView().onLoadError(bean.getMsg());
                            }
                        } catch (Exception e) {
                        }
                    }
                });
    }
}
